package it.koutifaris.travianmap.view.serversettingsview;

import it.koutifaris.travianmap.context.ContextRetreiver;
import it.koutifaris.travianmap.dal.TravianServerService;
import it.koutifaris.travianmap.dal.TravianServerService.TravianServer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class ServerSettingsActivity extends Activity {

	private static final String TRAVIAN_SERVER_PARAM = "TRAVIAN_SERVER";

	public static void startActivity(Activity currentActivity) {
		Intent intent = new Intent(currentActivity, ServerSettingsActivity.class);
		currentActivity.startActivity(intent);
	}

	public static void startActivity(Activity currentActivity, TravianServerService.TravianServer travianServer) {
		Intent intent = new Intent(currentActivity, ServerSettingsActivity.class);
		intent.putExtra(TRAVIAN_SERVER_PARAM, travianServer);
		currentActivity.startActivity(intent);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		ContextRetreiver.contextRetreiver().setCurrentContext(this);

		TravianServer travianServer = getTravianServer();
		if (travianServer != null) {
			new ServerViewController().show(travianServer);
		} else {
			new ServerViewController().show();
		}
	}

	@Override
	protected void onRestart() {
		super.onRestart();
		ContextRetreiver.contextRetreiver().setCurrentContext(this);
	}

	private TravianServer getTravianServer() {
		TravianServer result = null;

		if (getIntent().getExtras() != null) {
			result = getIntent().getExtras().getParcelable(TRAVIAN_SERVER_PARAM);
		}

		return result;
	}

}
